<!--
描述：留言-添加
开发人：anliming
开发日期：2019年1月24日
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="TrainingMessage" ref="kalixBizDialog"
  v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" )
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-input(v-model="formModel.uid" type="hidden")
      el-form-item(label="院系" prop="did" v-bind:rules="rules.did" v-bind:label-width="labelWidth")
        el-cascader.long(placeholder="请选择院系信息" :options="options" filterable @change="getDep" :clearable="true" v-bind:show-all-levels="false" change-on-select)
      el-form-item(label="课程" prop="cid" v-bind:rules="rules.cid" v-bind:label-width="labelWidth")
        el-select(v-model="formModel.cid" placeholder="请选择课程")
          el-option(v-for="item in items" :key="item.value" :label="item.label" :value="item.value" )
      el-form-item(label="评论内容" prop="content" label-width="120px" v-bind:rules="rules.content")
        el-input(v-model="formModel.content" style="width:80%")
      el-form-item(label="评分" prop="score" label-width="120px" v-bind:rules="rules.score")
        el-input(v-model="formModel.score" style="width:80%" @keyup.native="proving")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {trainingMessageURL, DepartmentsURL, TrainingVideosUrl} from '../../config.toml'
  export default {
    name: 'trainingMessageAdd',
    data() {
      return {
        formModel: Object.assign({}, FormModel),
        rules: {
          content: [{required: true, message: '请输入评论内容', trigger: 'blur'}],
          score: [{required: true, message: '请输入评分', trigger: 'blur'}]
        },
        targetURL: trainingMessageURL,
        labelWidth: '110px',
        items: [],
        options: []
      }
    },
    mounted() {
      this.getDepCascader() // 获取院系信息并以级联形式显示
      // this.formModel.uid = this.$KalixCatch.get('id')
    },
    methods: {
      proving() {
        this.formModel.score = this.formModel.score.replace(/[^\d]/g, '')
        this.formModel.score = this.formModel.score.replace('.', '')
      },
      init(dialogOption) {
        console.log('---------this.formModel.uid------------', this.formModel.uid)
        this.formModel.uid = this.$KalixCatch.get('id')
      },
      getDepCascader() { // 获取院系信息并以级联形式显示
        console.log('getDepCascader========================')
        this.axios.request({
          method: 'GET',
          url: DepartmentsURL + '/getDepCascader'
        }).then(res => {
          console.log('getDepCascader==============', res.data.data)
          this.options = res.data.data
        })
      },
      getDep(val) { // 通过级联获取数据后转成字符串
        let ddid = val.toString().substring(val.toString().lastIndexOf(',') + 1, val.toString().length)
        console.log('ddid========================', ddid)
        this.axios.request({
          method: 'GET',
          url: TrainingVideosUrl + '/getDDidBySelect',
          params: {
            did: ddid
          }
        }).then(res => {
          console.log('getDDidBySelect==============', res.data.data)
          this.items = res.data.data
        })
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
</style>
